from google.appengine.ext import webapp
from google.appengine.ext.webapp import util
from google.appengine.api import users
from mako.template import Template
from mako.lookup import TemplateLookup

from models.project import MasterControlProject

class ProjectHandler(webapp.RequestHandler):
    def get(self, mcp_code):
        user = users.get_current_user()
        project = MasterControlProject.get_by_key_name(mcp_code)
        base_url = self.request.host_url
        if project.owner != user:
            return self.redirect('/secure/')
        temp = Template(filename = 'templates/project.html', lookup = TemplateLookup(directories = ['.']))
        self.response.out.write(temp.render(user = user, project = project, base_url = base_url))